package com.one.pass.util;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

//MapUtils类提供了一些静态方法，用于将可变参数键值对转换为不同类型的Map
public class MapUtils {

    // 将可变参数键值对转换为Map
    public static Map<String, Object> asMap(Object... keys) {
        Map<String, Object> map = new HashMap<>();
        for (int i = 0; i < keys.length / 2; i++) {
            map.put(keys[i * 2].toString(), keys[i * 2 + 1]);
        }
        return map;
    }

    // 将可变参数字符串键值对转换为Map<String, String>
    public static Map<String, String> asMapStr(String... keys) {
        Map<String, String> map = new HashMap<>();
        for (int i = 0; i < keys.length / 2; i++) {
            map.put(keys[i * 2], keys[i * 2 + 1]);
        }
        return map;
    }

    // 将可变参数键值对转换为LinkedHashMap
    public static Map<String, Object> asLinkMap(Object... keys) {
        Map<String, Object> map = new LinkedHashMap<>();
        for (int i = 0; i < keys.length / 2; i++) {
            map.put(keys[i * 2].toString(), keys[i * 2 + 1]);
        }
        return map;
    }

    // 将可变参数键值对转换为泛型Map
    public static <T> Map<T, T> asMapT(T... keys) {
        Map<T, T> map = new HashMap<>();
        for (int i = 0; i < keys.length / 2; i++) {
            map.put(keys[i * 2], keys[i * 2 + 1]);
        }
        return map;
    }
}
